package com.rico.deploy.service.impl;

import com.rico.deploy.entity.User;
import com.rico.deploy.entity.UserLoginLog;
import com.rico.deploy.entity.Userlogin;
import com.rico.deploy.mapper.UserLoginLogMapper;
import com.rico.deploy.mapper.UserloginMapper;
import com.rico.deploy.service.UserloginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author 吴泽胜
 * @FileName UserloginServiceImpl
 * @date 2021-04-23 5:04 下午
 * @Software: IntelliJ IDEA
 */
@Service
public class UserloginServiceImpl implements UserloginService {

    @Autowired
    private UserloginMapper userloginMapper;

    @Autowired
    private UserLoginLogMapper userLoginLogMapper;

    @Override
    public Userlogin selectUserloginByUAndP(String username, String password) {
        Example example = new Example(Userlogin.class);
        example.createCriteria()
                .andEqualTo("username",username)
                .andEqualTo("password",password)
                .andEqualTo("status", 1);
        Userlogin userlogin = userloginMapper.selectOneByExample(example);
        //插入登录日志
        if ( userlogin != null ){
            userLoginLogMapper.insert(new UserLoginLog(username));
        }
        return userlogin;
    }

}
